<?php
/**
 * 文章接口
 */
class ArticleController extends \Our\Controller_AbstractApi {

    /**
     * 文章列表
     */
    public function listAction(){
        $mysql = \Mysql\ArticleModel::getInstance();
        $cat_id = $this->getRequest()->getPost("cat_id", 0);
        $type = $this->getRequest()->getPost("type", 'up');
        $time = CommonFun::local_format_time('',$this->getRequest()->getParam("time", CommonFun::local_time()));
        $page = $this->getRequest()->getPost("page", 1);
        $columns = array('article_id','cat_id','title','thumb','type','add_time');
        $where = 'status=1';
        if(!empty($cat_id))$where.=' AND cat_id='.$cat_id;
        if($type=='up'){
            $where.=" AND add_time<='".$time."'";
            $order = 'add_time desc';
        }elseif($type='down'){
            $where.=" AND add_time>='".$time."'";
            $order = 'add_time asc';
        }
        $limit = '10';
        $data  = $mysql->getPageList($where,$limit,$page,$order,$columns);
        echo $this->jsonEncode($this->apiData($data));
    }

    /**
     * 文章详情
     */
    public function infoAction(){
        $aid = $this->getRequest()->getParam("aid", 0);
        $mysql = \Mysql\ArticleModel::getInstance();
        $row = $mysql->getRow($aid);
        if(!empty($row)){
            echo $this->jsonEncode($this->apiData($row));
        }else{
            echo $this->jsonEncode($this->apiData('该数据不存在或者已被禁用!',1));
        }
    }
}
